package com.llsydn.demo.music;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.llsydn.hello.R;

/**
 * @author lilinshen
 * @title 播放音乐demo
 * @description 请填写相关描述
 * @date 2018/9/29 14:20
 */
public class MusicActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn_main_play;
    private Button btn_main_stop;
    private Button btn_main_pause;
    private Button btn_main_exit;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music);

        btn_main_play = findViewById(R.id.btn_main_play);
        btn_main_stop = findViewById(R.id.btn_main_stop);
        btn_main_pause = findViewById(R.id.btn_main_pause);
        btn_main_exit = findViewById(R.id.btn_main_exit);

        btn_main_play.setOnClickListener(this);
        btn_main_stop.setOnClickListener(this);
        btn_main_pause.setOnClickListener(this);
        btn_main_exit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this, MusicService.class);
        if (v == btn_main_play) {
            intent.putExtra("action", "play");
            startService(intent);
        } else if (v == btn_main_stop) {
            intent.putExtra("action", "stop");
            startService(intent);
        } else if (v == btn_main_pause) {
            intent.putExtra("action", "pause");
            startService(intent);
        } else if (v == btn_main_exit) {
            stopService(intent);
            finish();
        }
    }

}
